/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BookViewPanel.java
 *
 * Created on 1-gen-2014, 17.43.31
 */
package APP3.bookshop.gui;

import APP3.bookshop.book.ABook;
import APP3.bookshop.book.ElectronicBook;
import APP3.bookshop.book.PaperBook;
import APP3.bookshop.main.BookShop;
import APP3.bookshop.person.author.Author;
import javax.swing.JLabel;

public class BookViewPanel extends javax.swing.JPanel {

    private BookShop bookshop;

    /**
     * Creates new form BookViewPanel
     */
    public BookViewPanel(BookShop b) {
        this.bookshop = b;
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel5 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        BookList = new javax.swing.JList();
        bookTitleLabel = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel6 = new javax.swing.JLabel();
        BookView_BookURLTextField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        BookView_bookPUblisherTextField = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        BookView_bookAuthorsList = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();
        viewBook_BookPublishingDatePicker = new org.jdesktop.swingx.JXDatePicker();

        jLabel5.setText("jLabel5");

        jLabel1.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N
        jLabel1.setText("View book");

        jLabel2.setFont(new java.awt.Font("Lucida Grande", 0, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(51, 51, 51));
        jLabel2.setText("Select a book to view related information");

        BookList.setModel(bookshop.getBookmanager().populateBookList());
        BookList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                BookListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(BookList);

        bookTitleLabel.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N
        bookTitleLabel.setText("TITLE BOOK");

        jLabel4.setForeground(new java.awt.Color(51, 51, 51));
        jLabel4.setText("Publishing date");

        jLabel6.setForeground(new java.awt.Color(51, 51, 51));
        jLabel6.setText("URL");

        BookView_BookURLTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BookView_BookURLTextFieldActionPerformed(evt);
            }
        });

        jLabel7.setForeground(new java.awt.Color(51, 51, 51));
        jLabel7.setText("Publisher");

        jLabel8.setForeground(new java.awt.Color(51, 51, 51));
        jLabel8.setText("Authors");

        jScrollPane2.setViewportView(BookView_bookAuthorsList);

        jButton1.setText("Delete book");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 377, Short.MAX_VALUE)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 377, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jLabel1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 66, Short.MAX_VALUE)
                        .add(jLabel2))
                    .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 377, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jLabel6)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(BookView_BookURLTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jLabel7)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(BookView_bookPUblisherTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 309, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(0, 0, Short.MAX_VALUE)
                        .add(jButton1))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(bookTitleLabel)
                            .add(jLabel8))
                        .add(0, 0, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(jLabel4)
                        .add(18, 18, 18)
                        .add(viewBook_BookPublishingDatePicker, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jLabel2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 110, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(bookTitleLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(viewBook_BookPublishingDatePicker, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel6)
                    .add(BookView_BookURLTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel7)
                    .add(BookView_bookPUblisherTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel8)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 96, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jButton1)
                .addContainerGap(24, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void BookView_BookURLTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BookView_BookURLTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_BookView_BookURLTextFieldActionPerformed

    private void BookListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_BookListMouseClicked
        ABook selectedBook = (ABook) BookList.getSelectedValue();
        this.bookTitleLabel.setText(selectedBook.getTitle());
        this.viewBook_BookPublishingDatePicker.setDate(selectedBook.getPublishingDate());
        this.BookView_bookPUblisherTextField.setText(selectedBook.getPublisher().getName());

        if (selectedBook instanceof ElectronicBook) {
            this.BookView_BookURLTextField.setEnabled(true);
            this.BookView_BookURLTextField.setText(((ElectronicBook) selectedBook).getCode());
        } else if (selectedBook instanceof PaperBook) {
            this.BookView_BookURLTextField.setEnabled(false);
        }
        
        BookView_bookAuthorsList.setModel(bookshop.getBookmanager().populateBookAuthorsList(selectedBook));

    }//GEN-LAST:event_BookListMouseClicked

    public JLabel getBookTitleLabel() {
        return bookTitleLabel;
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList BookList;
    private javax.swing.JTextField BookView_BookURLTextField;
    private javax.swing.JList BookView_bookAuthorsList;
    private javax.swing.JTextField BookView_bookPUblisherTextField;
    private javax.swing.JLabel bookTitleLabel;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private org.jdesktop.swingx.JXDatePicker viewBook_BookPublishingDatePicker;
    // End of variables declaration//GEN-END:variables

}
